package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.WorksBean;
import com.dlwx.parttimetalent.inter.PositionInter;
import com.dlwx.parttimetalent.utils.LogUtils;

/**
 * Created by Administrator on 2017/11/21.
 */

public class WorkExperienceAdapter extends BaseMultiAdapter<WorksBean.BodyBean>  {
    private  Context context;
    private PositionInter inter;
    public WorkExperienceAdapter(Context context,PositionInter inter) {
        super(context);
        this.context=context;
        this.inter=inter;
    }
    {
        addItemType(0,R.layout.item_work_experience);
        addItemType(1,R.layout.item_work_add);
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {
        WorksBean.BodyBean bean = getDataList().get(position);
        switch (bean.getType()){
            case 0:
                bindDatas(holder,bean,position);
                break;
            case 1:
                bindAdd(holder,bean,position);
                break;
        }
    }

    private void bindAdd(SuperViewHolder holder, WorksBean.BodyBean bean, int position) {
        TextView tv_add=holder.getView(R.id.tv_add1);
        tv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                inter.callBack(0);
            }
        });
    }

    private void bindDatas(SuperViewHolder holder, WorksBean.BodyBean bean, final int position) {
        TextView tvTime=holder.getView(R.id.tv_time);
        TextView tvUnit=holder.getView(R.id.tv_unit);
        Button deleteBtn=holder.getView(R.id.btnDelete);
            tvUnit.setText(bean.getJob_info());
        tvTime.setText(bean.getStart()+"~"+bean.getEnd());
        deleteBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnSwipeListener.onDel(position);
            }
        });
    }

    /**
     * 和Activity通信的接口
     */
    public interface onSwipeListener {
        void onDel(int pos);

        void onTop(int pos);
    }

    private onSwipeListener mOnSwipeListener;

    public void setOnDelListener(onSwipeListener mOnDelListener) {
        this.mOnSwipeListener = mOnDelListener;
    }
}
